package wave.common.pojo.entity;

import com.mybatisflex.core.paginate.Page;

import java.util.List;
import java.util.stream.Collectors;

public abstract class BaseWrapper<T, R> {

    public abstract R entityVO(T entity);

    public List<R> listVO(List<T> list) {
        return list.stream().map(this::entityVO).collect(Collectors.toList());
    }

    public Page<R> pageVO(Page<T> pages) {
        List<R> records = this.listVO(pages.getRecords());
        Page<R> pageVo = new Page<>(pages.getPageNumber(), pages.getPageSize(), pages.getTotalRow());
        pageVo.setRecords(records);
        return pageVo;
    }

}
